﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Xww.LCV.Model {
    ///<summary>表示蛋白质序列的双向字符串链表
    ///每个节点表示一个氨基酸
    /// </summary>
    public class SequencePath : LinkedList<string> {

        public override string ToString() {
            StringBuilder rst = new StringBuilder();
            rst.Append("Fist : ");
            LinkedListNode<string> node = this.First;
            while (node != null) {
                rst.AppendFormat("{0} ", node.Value);
                node = node.Next;
            }
            rst.Append(" : Last");
            return rst.ToString();
        }
        /// <summary>用于构建的源蛋白质序列</summary>
        public string Sequence { get; private set; }

        #region static

        ///<summary>由一组字符串创建序列路径（多用于语言学分析，即组成单元为单词等多字符单元）</summary>
        public static SequencePath Create(IEnumerable<string> source) {
            SequencePath rst = new SequencePath();
            rst.AddFirst("→");
            foreach (string item in source) {
                rst.AddLast(item);
            }
            rst.AddLast("←");
            return rst;
        }
        ///<summary>由一个字符串中的所有字符创建序列路径（多用于生物信息学蛋白质序列）</summary>
        public static SequencePath Create(string source) {
            SequencePath rst = new SequencePath();
            rst.AddFirst("→");
            foreach (char item in source) {
                rst.AddLast(item.ToString());
            }
            rst.AddLast("←");
            rst.Sequence = source;
            return rst;
        }

        #endregion
    }
}
